package cn.net.csit.platform_cloud.basicmodel.controller;

import cn.net.csit.platform_cloud.basicmodel.domain.BasicPropertyGroupDomain;
import cn.net.csit.platform_cloud.basicmodel.service.IBasicPropertyGroupService;
import cn.net.csit.platform_cloud.utils.BaseResult;
import cn.net.csit.platform_cloud.utils.ResultUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 * 属性组管理
 *
 * @ClassName:BasicPropertyGroupController
 *
 * @Author:yanwenjuan
 *
 * @Date:2019年4月2日
 *
 * @Description:属性组管理
 *
 *
 */

@RestController
@RequestMapping(value = "/propGroup")
public class BasicPropertyGroupController {
    @Autowired
    IBasicPropertyGroupService iBasicPropertyGroupService;


    //1.增加一条记录--insert
    @PostMapping("/insert")
    public BaseResult insert(@RequestBody BasicPropertyGroupDomain record){
        int i = iBasicPropertyGroupService.insert(record);
        return ResultUtil.success(i);
    }


    //2.查询所有记录--不分页--getAll
    @GetMapping("/getAll")
    public BaseResult getAll(){
        List<BasicPropertyGroupDomain> list = iBasicPropertyGroupService.getAll();
        PageInfo<BasicPropertyGroupDomain> info = new PageInfo<>(list);
        return  ResultUtil.success(info);
    }
    //2.2查询属性组下拉框--不分页--getAllMap
    @GetMapping("/getAllMap")
    public BaseResult getAllMap(){
        List<Map<String,String>> list = iBasicPropertyGroupService.getAllMap();
        PageInfo<Map<String,String>> info = new PageInfo<>(list);
        return  ResultUtil.success(info);
    }
    //3.查询所有记录--分页--getAllByPage
    @GetMapping("/getAllByPage")
    public BaseResult getAllByPage(Pageable pageable){
        PageHelper.startPage(pageable.getPageNumber(),pageable.getPageSize());
        List<BasicPropertyGroupDomain> list=iBasicPropertyGroupService.getAll();
        PageInfo<BasicPropertyGroupDomain> info=new PageInfo<>(list);
        return ResultUtil.success(info);
    }
    //4.查询所有--条件查询--getAllChooseByPage
    @GetMapping("/getAllChooseByPage")
    public BaseResult getAllChooseByPage() {
        Map<String, String> map = new HashMap<>();
        map.put("propGroupName","group1");
        List<BasicPropertyGroupDomain> list = iBasicPropertyGroupService.getAll(map);
        return ResultUtil.success(list);
    }


    //5.根据主键uuid，删除一条记录--deleteByPrimaryKey
    @PostMapping("/deleteByPrimaryKey")
    public BaseResult deleteByPrimaryKey(String uuid){
       int i = iBasicPropertyGroupService.deleteByPrimaryKey(uuid);
       return ResultUtil.success(i);
    }

    //6.根据属性组名称，删除一条记录

    //7.根据主键，查询一条记录--getByPK
    @PostMapping("/getByPK")
    public BaseResult getByPK(String uuid){
       BasicPropertyGroupDomain model = iBasicPropertyGroupService.selectByPrimaryKey(uuid);
       return ResultUtil.success(model);
    }

    //8.根据主键，修改一条记录--updateByPrimaryKey
    @PostMapping("/updateByPrimaryKey")
    public BaseResult updateByPrimaryKey(@RequestBody BasicPropertyGroupDomain record){
        int i = iBasicPropertyGroupService.updateByPrimaryKey(record);
        return ResultUtil.success(i);
    }
    //0.查询属性组集合-有条件（属性组名称），分页
    @PostMapping("/getAllByGN")
    public BaseResult getAllByGN(String propGroupName){
        Map<String,String> map = new HashMap<>();
        map.put("prop_group_name",propGroupName);
        Map<String,String> map1 = iBasicPropertyGroupService.getAllByGN(map);
        return ResultUtil.success(map1);
    }


}
